<?php
declare (strict_types = 1);

namespace app\controller;

use app\common\model\ArticleCate;
use app\common\model\ArticleOrder;
use app\common\model\Comment;
use app\common\model\Content;
use app\common\model\User;
use think\facade\Cache;
use think\facade\Db;
use think\facade\Session;
use think\facade\View;
use think\Request;

class Test extends Common
{
    /**
     * 显示资源列表
     *
     * @return \think\Response
     */
    public function index()
    {
        $arr = [
            ["name"=>"王博","Monday"=>"秀周报能","Tuesday"=>"洗头发","Wednesday"=>"美甲","Thursday"=>"暂定","Friday"=>"总结"]
            ,["name"=>"李伦","Monday"=>"秀周报能","Tuesday"=>"洗头发","Wednesday"=>"美甲","Thursday"=>"暂定","Friday"=>"总结"]
            ,["name"=>"陈曦","Monday"=>"秀周报能","Tuesday"=>"洗头发","Wednesday"=>"美甲","Thursday"=>"暂定","Friday"=>"总结"]
            ,["name"=>"邓支航","Monday"=>"秀周报能","Tuesday"=>"洗头发","Wednesday"=>"美甲","Thursday"=>"暂定","Friday"=>"总结"]
            ,["name"=>"吴海艳","Monday"=>"秀周报能","Tuesday"=>"洗头发","Wednesday"=>"美甲","Thursday"=>"暂定","Friday"=>"总结"]
            ,["name"=>"张良","Monday"=>"秀周报能","Tuesday"=>"洗头发","Wednesday"=>"美甲","Thursday"=>"暂定","Friday"=>"总结"]
            ,["name"=>"宋涛","Monday"=>"秀周报能","Tuesday"=>"洗头发","Wednesday"=>"美甲","Thursday"=>"暂定","Friday"=>"总结"]
            ,["name"=>"周明明","Monday"=>"秀周报能","Tuesday"=>"洗头发","Wednesday"=>"美甲","Thursday"=>"暂定","Friday"=>"总结"]
            ,["name"=>"徐欢","Monday"=>"秀周报能","Tuesday"=>"洗头发","Wednesday"=>"美甲","Thursday"=>"暂定","Friday"=>"总结"]
            ,["name"=>"闫珅祥","Monday"=>"秀周报能","Tuesday"=>"洗头发","Wednesday"=>"美甲","Thursday"=>"暂定","Friday"=>"总结"]
            ,["name"=>"张煜","Monday"=>"秀周报能","Tuesday"=>"洗头发","Wednesday"=>"美甲","Thursday"=>"暂定","Friday"=>"总结"]
            ,["name"=>"肖蜜蜜","Monday"=>"秀周报能","Tuesday"=>"洗头发","Wednesday"=>"美甲","Thursday"=>"暂定","Friday"=>"总结"]
        ];
        return json($arr);
        p($arr);
        die;

        //标签库测试
        return \view();
        die();
        //用户头像 半路 替换
        $list = User::where("headimgurl","like","%https://micuer.com/%")->select()->toArray();
        foreach ($list as $k => $v){
            $v = $v["headimgurl"];
            $v = str_replace("https://micuer.com/","/",$v);
            $list[$k]["headimgurl"] = $v;
            unset($list[$k]["reg_time"]);
            unset($list[$k]["last_time"]);
        }
        $user = new User();

        $user->saveAll($list);
        p($list);

        die(222);
        //批量替换 彼岸图网
        $list = Content::where("title","like","%彼岸图网%")->field("id,title")->select()->toArray();
        foreach ($list as $k => $v){
            $title = str_replace("彼岸图网","米醋儿网",$v["title"]);
            $list[$k]["title"] = $title;
        }

        $user = new Content();
        $user->saveAll($list);

        p($list);
        p(222);
        die;


        //自动生成用户头像
        //https://micuer.com/data/upload/20200715head/micuer_avator%20({$i}).jpg  上次任务只执行到了 36 一共有53个头像
        $users = User::where("headimgurl",'')->select()->toArray();
        echo "一共有".count($users)."个用户";
        $i = 36;
        $success = 0;
        $error = 0;
        foreach ($users as $v){
            $temp = "https://micuer.com/data/upload/20200715head/micuer_avator%20({$i}).jpg";
            $i++;
            $v["headimgurl"] = $temp;
            $v["reg_time"] = strtotime($v["reg_time"]);
            $v["last_time"] = strtotime($v["last_time"]);

            $res = User::where("id",$v["id"])->save($v);

            if($res){
                $success++;
            }else{
                $error ++;
            }
        }


        p("本次任务成功".$success."人，失败".$error."人");


       p("http://micuer.com/data/upload/20200715head/micuer_avator%20(53).jpg");
    }

}
